#!/usr/bin/env python3
"""
最简版API连接器演示 - 只保留核心功能
"""

# 静态数据示例
STATIC_DATA = {
    "users": [
        {"id": 1, "name": "张三", "email": "zhangsan@example.com"},
        {"id": 2, "name": "李四", "email": "lisi@example.com"},
        {"id": 3, "name": "王五", "email": "wangwu@example.com"}
    ],
    "posts": [
        {"id": 1, "title": "第一篇文章", "content": "这是第一篇文章的内容", "userId": 1},
        {"id": 2, "title": "第二篇文章", "content": "这是第二篇文章的内容", "userId": 2},
        {"id": 3, "title": "第三篇文章", "content": "这是第三篇文章的内容", "userId": 1}
    ]
}

class MinimalAPIConnector:
    """最简版API连接器"""
    
    def __init__(self):
        # API配置（简化版）
        self.config = {
            "static_data": {
                "endpoints": {
                    "get_users": {"description": "获取用户列表"},
                    "get_posts": {"description": "获取文章列表"}
                }
            }
        }
    
    def call_api(self, endpoint_name: str):
        """调用API端点"""
        try:
            if endpoint_name == "get_users":
                return True, "获取用户列表成功", STATIC_DATA["users"]
            elif endpoint_name == "get_posts":
                return True, "获取文章列表成功", STATIC_DATA["posts"]
            else:
                return False, f"端点不存在: {endpoint_name}", None
        except Exception as e:
            return False, f"API调用异常: {str(e)}", None

def main():
    """主函数 - 演示核心功能"""
    print("🚀 最简版API连接器演示")
    print("=" * 30)
    
    # 初始化API连接器
    connector = MinimalAPIConnector()
    print("✅ API连接器初始化完成")
    
    # 调用API获取用户数据
    print("\n📡 调用API获取用户数据...")
    success, message, users_data = connector.call_api("get_users")
    if success:
        print(f"✅ {message}")
        print("用户列表:")
        for user in users_data:
            print(f"  - {user['name']} ({user['email']})")
    else:
        print(f"❌ {message}")
    
    # 调用API获取文章数据
    print("\n📡 调用API获取文章数据...")
    success, message, posts_data = connector.call_api("get_posts")
    if success:
        print(f"✅ {message}")
        print("文章列表:")
        for post in posts_data:
            print(f"  - {post['title']} (用户ID: {post['userId']})")
    else:
        print(f"❌ {message}")
    
    print("\n🎉 演示完成!")

if __name__ == "__main__":
    print("------>>>最小的一个demo,去掉了所有的真实API接口!")
    main()